cmake_minimum_required(VERSION 2.8)
project(whitebox C)

# set(CMAKE_C_FLAGS "-g -w -Wall -Werror -rdynamic -D_GUN_SOURCE -D_REENTRANT")
# TODO for Ubuntu etc
if (EXISTS "${CMAKE_SOURCE_DIR}/__testing__")
    set (CMAKE_C_FLAGS "-std=c99 -fms-extensions -g -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -fPIC -rdynamic -D_GNU_SOURCE -D_REENTRANT -D_FILE_OFFSET_BITS=64")
else()
    # for centos6,centos7 etc
    set (CMAKE_C_FLAGS "-std=c99 -fms-extensions -g -Wall -Werror ${NO_WARN} -fPIC -rdynamic -D_GNU_SOURCE -D_REENTRANT -D_FILE_OFFSET_BITS=64")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(LICH_HOME "${CMAKE_SOURCE_DIR}/..")

# set lsv dir
set (LSV_HOME "${LICH_HOME}/lsv")
set (LSV_SRC "${LICH_HOME}/lsv")

include_directories(
    /usr/local/include

    ${LICH_HOME}/include
    ${LICH_HOME}/ylib/gdsl/include
    ${LICH_HOME}/libetcd
    ${LICH_HOME}/config/include
    ${LICH_HOME}/ylib/include
    ${LICH_HOME}/ynet/include
    ${LICH_HOME}/cluster/include
    ${LICH_HOME}/schedule
    ${LICH_HOME}/storage/storage
    ${LICH_HOME}/storage/controller
    ${LICH_HOME}/storage/lease
    ${LICH_HOME}/storage/qos
    ${LICH_HOME}/storage/chunk
    ${LICH_HOME}/storage/replica
    ${LICH_HOME}/storage/replica/diskmd
    ${LICH_HOME}/storage/replica/diskmd/disk
    ${LICH_HOME}/storage/replica/diskmd/disk_mapping

    ${LICH_HOME}/iscsi/include
    include
    ${LSV_SRC}/include
    ${LSV_SRC}/src/volume
    )

message(${LICH_HOME})

link_directories(
    /usr/local/lib
    "${LICH_HOME}/cb"
    "${LICH_HOME}/cmakebuild"
    )
set(LIBS lich4s sqlite3 uuid pthread aio crypt crypto ssl rt m hiredis cmocka curl yajl rdmacm numa pciaccess ibverbs)

function(build_tool name source_files libs)
    add_executable(${name} ${source_files})
    target_link_libraries(${name} ${libs})
endfunction()

# set(TEST_LIST_SRC_FILES src/test_list.c)
# build_tool(test_list "${TEST_LIST_SRC_FILES}" "${LIBS}")

# set(TEST_QSORT_SRC_FILES src/test_qsort.c)
# build_tool(test_qsort "${TEST_QSORT_SRC_FILES}" "${LIBS}")

# set(BUCKET_SRC_FILES src/test_bucket.c)
# build_tool(test_bucket "${BUCKET_SRC_FILES}" "${LIBS}")

# set(VEC_SRC src/test_vec.c)
# build_tool(test_vec "${VEC_SRC}" "${LIBS}")

#set(BITMAP_SRC src/test_bitmap.c)
#build_tool(test_bitmap "${BITMAP_SRC}" "${LIBS}")

# set(SKIPLIST_SRC src/test_skiplist.c src/_strings.c)
# build_tool(test_skiplist "${SKIPLIST_SRC}" "${LIBS}")

# set(RBTREE_SRC src/rbtree.c)
# build_tool(rbtree "${RBTREE_SRC}" "${LIBS}")

# set(BUF_SRC src/buffer.c)
# build_tool(buf "${BUF_SRC}" "${LIBS}")

#set(TEST_BUFFER_SRC src/test_buffer.c)
#build_tool(test_buffer "${TEST_BUFFER_SRC}" "${LIBS}")

set(TEST_REDIS_SRC src/test_redis.c)
build_tool(test_redis "${TEST_REDIS_SRC}" "${LIBS}")

set(TEST_BUFFER_SRC src/test_buffer.c)
build_tool(test_buffer "${TEST_BUFFER_SRC}" "${LIBS}")

set(TEST_ROW2_SRC src/test_row2.c)
build_tool(test_row2 "${TEST_ROW2_SRC}" "${LIBS}")

set(RE_SRC src/test_re.c)
build_tool(test_re "${RE_SRC}" "${LIBS}")

#set(TEST_MISC_SRC src/test_misc.c)
#build_tool(test_misc "${TEST_MISC_SRC}" "${LIBS}")

set(TEST_THREAD_SRC src/test_thread.c)
build_tool(test_thread "${TEST_THREAD_SRC}" "${LIBS}")
